from django.contrib import admin

# Register your models here.
from django.contrib import admin
from .models import Task, TaskImage
from django.contrib import admin
from .models import Task, TaskImage


class TaskImageInline(admin.TabularInline):
    model = TaskImage
    extra = 1


@admin.register(Task)
class TaskAdmin(admin.ModelAdmin):
    list_display = ('title', 'Projectname', 'status', 'testprogress', 'due_date', 'assigned_to', 'created_by')
    list_filter = ('status', 'testprogress', 'due_date', 'startdate', 'enddate', 'assigned_to', 'created_by')
    search_fields = ('title', 'description', 'Projectname', 'system', 'ProjectManager', 'ProductManager')
    date_hierarchy = 'due_date'
    inlines = [TaskImageInline]
    fieldsets = (
        ('基本信息', {
            'fields': ('title', 'description', 'status')
        }),
        ('项目信息', {
            'fields': ('Projectname', 'system')
        }),
        ('人员角色', {
            'fields': ('ProjectManager', 'ProductManager', 'DevelopmentEngineer', 'TestEngineer', 'assigned_to')
        }),
        ('链接', {
            'fields': ('Demandlink', 'Testlink')
        }),
        ('日期和进度', {
            'fields': ('startdate', 'enddate', 'due_date', 'testschedule', 'testprogress')
        }),
        ('其他信息', {
            'fields': ('Picturedata', 'Remarks')
        }),
    )


# @admin.register(Task)
# class TaskAdmin(admin.ModelAdmin):
#     list_display = ('title', 'status', 'Projectname', 'due_date', 'assigned_to', 'created_by')
#     list_filter = (
#     'status', 'Projectname', 'system', 'ProjectManager', 'ProductManager', 'TestEngineer', 'DevelopmentEngineer')
#     search_fields = ('title', 'description', 'Projectname', 'system')
#     date_hierarchy = 'created_at'
#     inlines = [TaskImageInline]


@admin.register(TaskImage)
class TaskImageAdmin(admin.ModelAdmin):
    list_display = ('task', 'caption', 'uploaded_at')
    list_filter = ('uploaded_at',)
    search_fields = ('task__title', 'caption')
